package cn.ulc.socket.weapp.service.impl;

import cn.ulc.common.constant.enums.AvailableStatus;
import cn.ulc.socket.weapp.common.BaseService;
import cn.ulc.socket.weapp.model.dto.ActivityDTO;
import cn.ulc.socket.weapp.service.ActivityServ;
import cn.ulc.store.dao.ActivityDao;
import cn.ulc.store.dao.ActivityGoodsDao;
import cn.ulc.store.entity.Activity;
import cn.ulc.store.entity.ActivityGoods;
import cn.ulc.store.entity.Company;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@AllArgsConstructor
public class ActivityServImpl extends BaseService implements ActivityServ {
    ActivityDao activityDao;
    ActivityGoodsDao activityGoodsDao;
    @Override
    public ActivityDTO findByCode(String code) {
        ActivityDTO dto = new ActivityDTO();
        Company company = getCurrentCompany();
        Activity activity = activityDao.findByCode(company.getId(),code,AvailableStatus.AVAILABLE);
        if(activity!=null){
            List<ActivityGoods> goodsList = activityGoodsDao.findByActivityId(activity.getId());
            dto.setGoodsList(goodsList);
        }
        dto.setActivity(activity);
        return dto;
    }
}
